package com.klhappy.houyuan.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.klhappy.houyuan.R;
import com.klhappy.houyuan.bean.EvaluateBean;
import com.klhappy.houyuan.bean.GoodsAllBean;
import com.klhappy.houyuan.constant.UrlConstant;
import com.klhappy.houyuan.view.ImageManager;

import java.util.ArrayList;
import java.util.List;

import butterknife.ButterKnife;
import butterknife.InjectView;

/**
 * Created by MrPu on 15/12/10.
 */
public class ItemAdapter extends BaseAdapter {
    private Context mContext;
    private ArrayList<EvaluateBean.OrderDetail> orderDetail;

    public ItemAdapter(Context context, ArrayList<EvaluateBean.OrderDetail> orderDetail) {
        this.mContext = context;
        this.orderDetail = orderDetail;
    }

    @Override
    public int getCount() {
        return orderDetail.size();
    }

    @Override
    public Object getItem(int position) {
        return orderDetail.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        EvaluateBean.OrderDetail item = orderDetail.get(position);
        Holder holder = null;
        if(convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(R.layout.confirm_order_list_item, null);
            holder = new Holder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (Holder)convertView.getTag();
        }
        ImageManager.loadImage(UrlConstant.BASE_URL + item.getG_icon(), holder.ivImage);
        holder.tvDes.setText(item.getG_name());
        holder.tvPrice.setText(item.getG_price() + "/" + item.getG_unit());
        holder.tvCount.setText("x" + item.getNo());

        return convertView;
    }

    public static class Holder {
        @InjectView(R.id.iv_image) ImageView ivImage;
        @InjectView(R.id.tv_des) TextView tvDes;
        @InjectView(R.id.tv_price) TextView tvPrice;
        @InjectView(R.id.tv_count) TextView tvCount;

        public Holder(View view) {
            ButterKnife.inject(this, view);
        }
    }
}
